<?php
if (!defined('WEB_ROOT')) {
	exit;
}

$rowsPerPage = 5;

$sql = "SELECT sch.id, masach, tensach, namxb, nhaxb, hinhanh_thumb, nganh_id, tennganh, soluong, solantaiban
        FROM sach sch left join nganh ng on sch.nganh_id = ng.id
		WHERE sch.hieu_luc > 0
		ORDER BY sch.id desc";
//echo $sql;
$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage);
		
//$groupList = buildGroupOptions($mannc);
?> 
<!-- Begin one column window -->
<div class="onecolumn">
				<div class="header">
					<span>Giáo trình - tài liệu</span>
					<div class="switch" style="width:160px">
						<table width="140px" cellpadding="0" cellspacing="0">
						<tbody>
							<tr>
								<td>
									<input name="btnAddGroup" class="middle_switch" type="button" id="btnAddGroup" value="Thêm giáo trình - tài liệu"  style="width:140px" onClick="addBook()">
								</td>
							</tr>
						</tbody>
						</table>
					</div>
				</div>
				<br class="clear"/>
				<div class="content">
				<form action="processBook.php?action=addBook" method="post"  name="frmListBook" id="frmListBook">
				 <!--<table width="100%" border="0" cellspacing="0" cellpadding="2" class="text">
				  <tr>
				   <td align="right">View Groups in : 
					<select name="cboGroup" class="box" id="cboGroup" onChange="viewGroup();">
					 <option selected>All Group</option>
					<?php echo $groupList; ?>
				   </select>
				 </td>
				 </tr>
				</table>-->
				 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="data">
					  <tr id="listTableHeader"> 
						<th>Thông tin giáo trình - tài liệu</th>
						<th width="85" align="center">Số lượng XB</th>
						<th width="85" align="center">Số lần tái bản</th>
						<th width="30">Sửa</th>
						<th width="30">Xóa</th>
					  </tr>
				  <?php
					if (dbNumRows($result) > 0) {
					$i = 0;
					
					while($row = dbFetchAssoc($result)) {
						extract($row);
						if ($hinhanh_thumb) {
							$hinhanh_thumb = WEB_ROOT . 'images/book/' . $hinhanh_thumb;
						} else {
							$hinhanh_thumb = WEB_ROOT . 'images/no-image-small.png';
						}	
						if ($i%2) {
							$class = 'row1';
						} else {
							$class = 'row2';
						}
						$i += 1;
				?>
				  <tr class="<?php echo $class; ?>"> 	  
					  <td>
						<div class="info_img">
							<img src="<?php echo $hinhanh_thumb; ?>">
						</div>
						  <div class="info_detail">
							<ul>
								<li>Mã Sách:&nbsp;<strong><?php echo $masach; ?></strong></li>
								<li>Tên Sách:&nbsp;<strong><?php echo $tensach; ?></strong></li>
								<li>Nhà XB:&nbsp;<strong><?php echo $nhaxb; ?></strong></li>
								<li>Tên ngành:&nbsp;<strong><?php echo $tennganh; ?></strong></li>
							</ul>
						</div>
					  </td>
					   <td width="85" align="center"><?php echo $soluong; ?></td>
					   <td width="85" align="center"><?php echo $solantaiban; ?></td>
					   <td width="30" align="center"><a href="javascript:modifyBook(<?php echo $id; ?>, <?php echo (int)$nganh_id; ?>);">Sửa</a></td>
					   <td width="30" align="center"><a href="javascript:deleteBook(<?php echo $id; ?>);">Xóa</a></td>
				  </tr>
				  <?php
					} // end while
				?>
				  <tr> 
				   <td colspan="5" align="center">
				   <?php 
						echo $pagingLink;
				   ?></td>
				  </tr>
				<?php	
				} else {
				?>
				  <tr> 
				   <td colspan="5" align="center">Không có giáo trình - tài liệu nào</td>
				  </tr>
				  <?php
				}
				?>
				 </table>
				 <p>&nbsp;</p>
				</form>
			</div>
	</div>